<template>
  <div class="table">
    <table v-if="Object.keys(sysInfo).length != 0">
      <tr>
        <td>系统名称</td>
        <td>{{ systemName }}</td>
      </tr>
      <tr>
        <td>版本信息</td>
        <td>v2.0</td>
      </tr>
      <tr>
        <td>操作系统</td>
        <td>{{ sysInfo.osName }}</td>
      </tr>
      <tr>
        <td>系统版本</td>
        <td>{{ sysInfo.osVersion }}</td>
      </tr>
      <tr>
        <td>系统架构</td>
        <td>{{ sysInfo.osArch }}</td>
      </tr>
      <tr>
        <td>CPU核数</td>
        <td>{{ sysInfo.processors }}</td>
      </tr>
      <tr>
        <td>系统内存</td>
        <td>{{ sysInfo.totalPhysical + "MB" }}</td>
      </tr>
      <tr>
        <td>剩余内存</td>
        <td>{{ sysInfo.freePhysical + "MB" }}</td>
      </tr>
      <tr>
        <td>内存使用</td>
        <td>{{ sysInfo.memoryRate }}</td>
      </tr>
      <tr>
        <td>系统语言</td>
        <td>{{ sysInfo.userLanguage }}</td>
      </tr>
    </table>

    <table>
      <tr>
        <td>JVM信息</td>
        <td>{{ sysInfo.jvmName }}</td>
      </tr>
      <tr>
        <td>JVM版本</td>
        <td>{{ sysInfo.javaVersion }}</td>
      </tr>
      <tr>
        <td>JAVA_HOME</td>
        <td>{{ sysInfo.javaHome }}</td>
      </tr>

      <tr>
        <td>工作目录</td>
        <td>{{ sysInfo.userDir }}</td>
      </tr>

      <tr>
        <td>JVM占用内存</td>
        <td>{{ sysInfo.javaTotalMemory }}MB</td>
      </tr>
      <tr>
        <td>JVM空闲内存</td>
        <td>2</td>
      </tr>
      <tr>
        <td>JVM最大内存</td>
        <td>{{ sysInfo.javaFreeMemory }}MB</td>
      </tr>

      <tr>
        <td>当前用户</td>
        <td>{{ sysInfo.javaMaxMemory }}MB</td>
      </tr>

      <tr>
        <td>CPU负载</td>
        <td>{{ sysInfo.systemCpuLoad }}%</td>
      </tr>

      <tr>
        <td>系统时区</td>
        <td>{{ sysInfo.userTimezone }}</td>
      </tr>
    </table>
  </div>
</template>

<script>
// import Schart from 'vue-schart';
// import bus from '../common/bus';
export default {
  name: "config",
  data() {
    return {
      sysInfo: {
        // osName: "",
        // osVersion: "",
        // osArch: "",
        // processors: 0,
        // totalPhysical: 0,
        // freePhysical: 0,
        // memoryRate: 0,
        // userLanguage: "",
        // jvmName: "",
        // javaVersion: "",
        // javaHome: "",
        // userDir: "",
        // javaTotalMemory: 0,
        // javaFreeMemory: 0,
        // javaMaxMemory: 0,
        // userName: "",
        // systemCpuLoad: 0,
        // userTimezone: "",
      },
      systemName: "",
    };
  },
  methods: {
    getSysInfo() {
      this.$axios
        .get("/sys/info", {
          params: { _t: Date.now() },
        })
        .then(({ data: res }) => {
          console.log("系统首页", res);
          if (res.code !== 0) {
            return;
          }
          this.sysInfo = res.data;
        });
    },
  },
  created() {
    this.getSysInfo();
    switch (location.hostname) {
      case "vue.bangning.vip":
        this.systemName = "物联网设备管理系统";
        break;
      case "bm.bangning.vip":
        this.systemName = "再生资源商城管理系统";
        break;
      case "bn.bangning.vip":
        this.systemName = "垃圾分类数据管理平台";
        break;
      default:
        this.systemName = "物联网设备管理系统";
        break;
    }
  },
};
</script>

<style scoped>
.table {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}
table tr td {
  border: 1px solid #aaa;
  line-height: 40px;
  text-align: center;
  color: rgba(0, 0, 0, 0.65);
}
table tr > td:first-child {
  font-size: 18px;
  color: rgba(0, 0, 0, 0.85);
  font-weight: bold;
}
table {
  width: 49%;
  border: none;
  border-collapse: collapse;
}
</style>
